package org.jsola.hr.helper;

import org.jsola.hr.dto.EventHandlingAddDTO;
import org.jsola.hr.dto.EventHandlingUpdateDTO;
import org.jsola.hr.entity.EventHandlingDO;
import org.jsola.hr.query.EventHandlingQuery;
import org.jsola.hr.service.IEventHandlingService;
import org.jsola.hr.vo.EventHandlingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 事件处理
 *
 * @author zhr
 */
@Component
public class EventHandlingTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEventHandlingService eventHandlingService;

    /**
     * 生成add测试数据
     * @return EventHandlingAddDTO
     */
    public EventHandlingAddDTO getEventHandlingAddDTO(){
        EventHandlingAddDTO eventHandlingAddDTO = new EventHandlingAddDTO();
        eventHandlingAddDTO.setCompanyId(getRandomValue("varchar",32));
        eventHandlingAddDTO.setCompanyName(getRandomValue("varchar",200));
        eventHandlingAddDTO.setMonth(getRandomValue("varchar",8));
        eventHandlingAddDTO.setEventTitle(getRandomValue("varchar",30));
        eventHandlingAddDTO.setEventLabel(getRandomValue("varchar",50));
        eventHandlingAddDTO.setEventContent(getRandomValue("text",2147483647));
        eventHandlingAddDTO.setEventAnnex(getRandomValue("varchar",2000));
        return eventHandlingAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EventHandlingUpdateDTO
     */
    public EventHandlingUpdateDTO getEventHandlingUpdateDTO(EventHandlingVO eventHandlingVO){
        return eventHandlingService.selectDOById(eventHandlingVO.getId(), SITE_ID).to(EventHandlingUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EventHandlingQuery
     */
    public EventHandlingQuery getEventHandlingQuery() {
        EventHandlingQuery eventHandlingQuery = new EventHandlingQuery();
        List<EventHandlingDO> eventHandlingDOList = eventHandlingService.list(new EventHandlingDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(eventHandlingDOList)) {
            EventHandlingDO eventHandlingDO = eventHandlingDOList.get(0);
            eventHandlingQuery = eventHandlingDO.to(EventHandlingQuery.class);
        }
        return eventHandlingQuery;
    }

    /**
     * 保存示例
     * @return EventHandlingVO
     */
    public EventHandlingVO saveEventHandlingExample(){
        EventHandlingAddDTO addDTO = this.getEventHandlingAddDTO();
        EventHandlingVO eventHandlingVO = eventHandlingService.save(addDTO,buildTokenUser());
        return eventHandlingVO;
    }


}

